
//
//  ChooseAddressViewController.m
//  LuxuryGoods
//
//  Created by DCQ on 2018/5/25.
//  Copyright © 2018年 Future. All rights reserved.
//

#import "ChooseAddressViewController.h"
#import "SearchAddressResultsViewController.h"

@interface ChooseAddressViewController ()<UISearchControllerDelegate,UISearchResultsUpdating>
@property (nonatomic,strong) UISearchController *searchController;
@property (nonatomic,strong) SearchAddressResultsViewController * searchResultVC;
@end

@implementation ChooseAddressViewController
- (SearchAddressResultsViewController *)searchResultVC{
    if (!_searchResultVC) {
        _searchResultVC = [[SearchAddressResultsViewController alloc]init];
    }
    return _searchResultVC;
}
- (UISearchController *)searchController{
    if (!_searchController) {
        //创建UISearchController
        _searchController = [[UISearchController alloc]initWithSearchResultsController:self.searchResultVC];
        //设置代理
        _searchController.delegate= self;
        _searchController.searchBar.delegate = self;
        [_searchController setSearchResultsUpdater: self.searchResultVC];
        //包着搜索框外层的颜色
        //    self.searchController.searchBar.barTintColor = [UIColor yellowColor];
        
        //提醒字眼
        _searchController.searchBar.placeholder= @"请输入关键字搜索";
        
        //提前在搜索框内加入搜索词
        
        
        //设置UISearchController的显示属性，以下3个属性默认为YES
        
        //搜索时，背景变暗色
        _searchController.dimsBackgroundDuringPresentation = YES;
        
        //搜索时，背景变模糊
        //    self.searchController.obscuresBackgroundDuringPresentation = NO;
        
        //点击搜索的时候,是否隐藏导航栏
        //    self.searchController.hidesNavigationBarDuringPresentation = NO;
        
        if (IOS8) {
            [[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitle:@"取消"];
        }else{
            
            [UIBarButtonItem appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]].title = @"取消";
        }
        
    }
    return _searchController;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationItemTitle:@"选择收货地址"];
    [self confighHeaderView];
}
- (void)confighHeaderView{
    
    //位置
    self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
    // 添加 searchbar 到 headerview
    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.searchResultVC.searchVC = self.searchController;
#warning 如果进入预编辑状态,searchBar消失(UISearchController套到TabBarController可能会出现这个情况),请添加下边这句话
    self.definesPresentationContext=YES;
    WEAKSELF
    self.searchResultVC.selectedBlock = ^(id model) {
       
    };
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
